/**
 * validate data
 * Created by walkskyer on 2016/2/16.
 */
(function($){
    $.wk_validate={
        test : function (reg, value) {
            if (typeof reg === "string") reg = new RegExp(reg);
            return reg.test(value);
        },
        isInt: function(value, allowMinus) {
            var reg;
            if (allowMinus) reg = /^-?\d+$/;
            else reg = /^\d+$/;
            return $.wk_validate.test(reg, value);
        },
        IntValidate: function(value, min, max) {
            if (typeof value !== "number") {
                if (!SCI.validate.isInt(value, true)) return false;
                value = parseInt(value);
            }
            return (min == null || value >= min) && (max == null || value <= max);
        },
        isNumber: function(value) {
            return $.wk_validate.test(/^-?\d+(.\d+)?$/, value);
        },
        isIDCardNumber: function(value) {
            return $.wk_validate.test(/^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$/, value);
        },
        isPhoneNumber: function(value, cellPhone) {
            if (cellPhone) return $.wk_validate.isMobileNumber(value);
            return $.wk_validate.test(/(^1\d{10}$)|(^(0\d{2,3}-)?(\d{7,8})(-\d{1,4})?$)/, value);
        },
        isMobileNumber: function (value) {
            return $.wk_validate.test(/^0{0,1}1(3|4|5|7|8)[0-9]{9}$/, value);
        },
        isEmail: function(email) {
            if (email.length > 100 || email.length < 6) {
                return false;
            }
            var format = /^[A-Za-z0-9+]+[A-Za-z0-9\.\_\-+]*@([A-Za-z0-9\-]+\.)+[A-Za-z0-9]+$/;
            if (!email.match(format)) {
                return false;
            }
            return true;
        }
    };
})(jQuery);